yii2-floor12-files.js ➔ stopCrop   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
1
console.log('Yii2 files model init.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
2
3
4
var currentCroppingImageId;
5
var currentRenamingFileId;
6
var cropper;
7
var removeFileOnCropCancel;
8
var yii2CropperRoute;
9
var yii2UploadRoute;
10
var uploaderSettings = {};
11
12
$(document).on('change', '.yii2-files-upload-field', function () {
13
14
    obj = $(this);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
15
16
    var formData = new FormData();
17
    formData.append('file', obj[0].files[0]);
18
    formData.append('modelClass', obj.data('modelclass'));
19
    formData.append('attribute', obj.data('attribute'));
20
    formData.append('mode', obj.data('mode'));
21
    formData.append('ratio', obj.data('ratio'));
22
    formData.append('name', obj.data('name'));
23
    formData.append('count', 1);
24
    formData.append('_fileFormToken', yii2FileFormToken);
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
26
27
    $.ajax({
28
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never initialized.
Loading history...
29
        type: 'POST',
30
        data: formData,
31
        processData: false,  // tell jQuery not to process the data
32
        contentType: false,  // tell jQuery not to set contentType
33
        success: function (response) {
34
            id = '#files-widget-block_' + obj.data('block');
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
35
            $(response).appendTo(id).find('div.floor12-files-widget-list');
36
        }
37
    });
38
});
39
40
41
function clipboard(text) {
42
    //based on https://stackoverflow.com/a/12693636
43
    document.oncopy = function (event) {
44
        event.clipboardData.setData("Text", text);
45
        event.preventDefault();
46
    };
47
    document.execCommand("Copy");
48
    document.oncopy = undefined;
49
    f12notification.info(text, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
50
}
51
52
function updateProgressCircle(val, btnGroup) {
53
    result = 169.646 * (1 - val / 100);
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
54
    btnGroup.querySelector('svg #progress-circle').setAttribute('stroke-dashoffset', result);
55
    btnGroup.querySelector('.floor12-file-percents').innerHTML = val + '%';
56
    // setAttribute('stroke-dashoffset', result);
57
}
58
59
var observer = new MutationObserver(function (mutations) {
0 ignored issues
show
Bug introduced by
The variable MutationObserver seems to be never declared. If this is a global, consider adding a /** global: MutationObserver */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
60
    percent = mutations[0].target.style.width.replace('%', '');
0 ignored issues
show
Bug introduced by
The variable percent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.percent.
Loading history...
61
    btnGroup = mutations[0].target.parentElement.parentElement;
0 ignored issues
show
Bug introduced by
The variable btnGroup seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.btnGroup.
Loading history...
62
    updateProgressCircle(percent, btnGroup);
63
});
64
65
var lastUploader = null;
66
67
function Yii2FilesUploaderSet(id, className, attribute, scenario, name) {
68
69
    var mode = 'multi';
70
    var blockName = "#" + id;
71
    var block = $(blockName);
72
    var uploadButton = block.find('button.btn-upload')[0];
73
    var filesList = block.find('.floor12-files-widget-list')[0];
74
    var ratio = 0;
75
76
    var csrf = block.parents('form').find('input[name=' + yii2CsrfParam + ']').val();
0 ignored issues
show
Bug introduced by
The variable yii2CsrfParam seems to be never declared. If this is a global, consider adding a /** global: yii2CsrfParam */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
78
    if (block.data('ratio'))
79
        ratio = block.data('ratio');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
80
81
    if (block.hasClass('floor12-files-widget-single-block')) {
82
        mode = 'single';
83
        toggleSingleUploadButton(block);
84
    }
85
86
    uploaderSettings[id] = {
87
        modelClass: className,
88
        attribute: attribute,
89
        scenario: scenario,
90
        mode: mode,
91
        name: name,
92
        ratio: ratio,
93
        count: block.find('.floor12-files-widget-list .floor12-file-object').length,
94
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
95
    }
96
97
    uploaderSettings[id][yii2CsrfParam] = csrf
98
    console.log(uploaderSettings[id]);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
99
    var uploader = new ss.SimpleUpload({
0 ignored issues
show
Bug introduced by
The variable ss seems to be never declared. If this is a global, consider adding a /** global: ss */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
100
        button: uploadButton,
101
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never initialized.
Loading history...
102
        name: 'file',
103
        dropzone: block,
104
        dragClass: 'floor12-files-widget-block-drug-over',
105
        multiple: true,
106
        multipleSelect: true,
107
        data: uploaderSettings[id],
108
        onSubmit: function (filename, extension, uploadBtn, size) {
0 ignored issues
show
Unused Code introduced by
The parameter extension is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter uploadBtn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter size is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
109
            uploaderSettings[id].count++;
110
            var svg = '\t<svg class="progress-circle" width="60" height="60" viewBox="0 0 60 60">\n' +
111
                '\t\t<circle cx="30" cy="30" r="27" fill="none" stroke="#ccc" stroke-width="5" />\n' +
112
                '\t\t<circle id="progress-circle" cx="30" cy="30" r="27" fill="none" stroke="#666" stroke-width="5" stroke-dasharray="169.646" stroke-dashoffset="169.646" />\n' +
113
                '\t</svg>';
114
115
            var fileId = generateId(filename);
116
            var btnGroup = document.createElement('div');
117
            var fileObject = document.createElement('div');
118
            var bar = document.createElement('div');
119
            var percents = document.createElement('div');
120
            btnGroup.setAttribute('id', fileId);
121
            btnGroup.className = 'btn-group files-btn-group';
122
            fileObject.className = 'floor12-file-object';
123
            percents.className = 'floor12-file-percents';
124
            this.setProgressBar(bar);
125
126
            fileObject.innerHTML = svg;
127
128
            observer.observe(bar, {
129
                attributes: true
130
            });
131
132
            fileObject.appendChild(bar);
133
            fileObject.appendChild(percents);
134
            btnGroup.appendChild(fileObject);
135
136
            if (mode == 'single') {
137
                $(filesList).html('');
138
            }
139
            $(filesList).append(btnGroup);
140
        },
141
        onComplete: function (filename, response) {
142
            if (!response) {
143
                console.log(filename + 'upload failed');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
144
                uploaderSettings[id].count--;
145
                return false;
146
            }
147
            f12notification.info(FileUploadedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileUploadedText seems to be never declared. If this is a global, consider adding a /** global: FileUploadedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
148
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
149
            $(idName).replaceWith($(response));
150
            if (mode == 'single')
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if mode == "single" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
151
                toggleSingleUploadButton(block);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
152
        },
153
        onError: function (filename, errorType, status, statusText, response, uploadBtn, fileSize) {
0 ignored issues
show
Unused Code introduced by
The parameter uploadBtn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter fileSize is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
154
            console.log(uploaderSettings[id]);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
155
            uploaderSettings[id].count--;
156
            data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
157
                responseText: response,
158
                status: status,
159
                statusText: statusText,
160
            };
161
            processError(data);
162
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
163
            $(idName).remove();
164
        }
165
166
        //     progressUrl: 'uploadProgress.php', // enables cross-browser progress support (more info below)
167
        //     responseType: 'json',
168
        //    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
169
        //   maxSize: 1024, // kilobytes
170
        //     hoverClass: 'ui-state-hover',
171
        //     focusClass: 'ui-state-focus',
172
        //     disabledClass: 'ui-state-disabled',
173
    });
174
    lastUploader = uploader;
175
}
176
177
function generateId(filename) {
178
    return 'id-' + filename.replace(/[^0-9a-zA-Z]/g, "");
179
}
180
181
function showUploadButton(event) {
182
    obj = $(event.target);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
183
    obj.parents('div.floor12-files-widget-single-block').find('button').show();
184
}
185
186
function toggleSingleUploadButton(block) {
187
    if (block.find('div.floor12-single-file-object').length > 0)
188
        block.find('button').hide();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
189
    else
190
        block.find('button').show();
191
}
192
193
function sortableFiles() {
194
    $(".floor12-files-widget-list-multi").sortable({
195
        opacity: 0.5,
196
        revert: 1,
197
        items: "div.files-btn-group",
198
        connectWith: ".floor12-files-widget-list-multi"
199
    });
200
}
201
202
function removeFile(id) {
203
    id = "#yii2-file-object-" + id;
204
    const blockId = $(id).parents('.files-widget-block').attr('id');
205
206
    $(id).parents('div.files-btn-group').fadeOut(200, function () {
207
        $(this).remove();
208
        f12notification.info(FileRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileRemovedText seems to be never declared. If this is a global, consider adding a /** global: FileRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
209
    });
210
211
    uploaderSettings[blockId].count--;
212
    return false;
213
}
214
215
function removeAllFiles(event) {
216
    console.log('removeAllFiles');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
217
    $(event.target).parents('div.floor12-files-widget-list').find('div.files-btn-group').fadeOut(200, function () {
218
        $(this).remove();
219
    });
220
    const blockId = $(event.target).parents('.floor12-files-widget-block').attr('id');
221
    uploaderSettings[blockId].count = 0;
222
    f12notification.info(FilesRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FilesRemovedText seems to be never declared. If this is a global, consider adding a /** global: FilesRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
223
    return false;
224
}
225
226
function initCropperLayout() {
227
    if (yii2CropperRoute.length > 0)
0 ignored issues
show
Bug introduced by
The variable yii2CropperRoute seems to be never initialized.
Loading history...
228
        $.get(yii2CropperRoute, function (response) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
229
            $('body').append(response);
230
231
            $('#yii2-file-title-editor input').on('keyup', function (e) {
232
                if (e.keyCode == 13) {
233
                    saveFileTitle()
234
                }
235
            });
236
        })
237
}
238
239
function initCropper(id, url, ratio, remove) {
240
    $('#cropperModal').modal({keyboard: false, backdrop: 'static'});
241
242
    currentCroppingImageId = id;
243
244
    removeFileOnCropCancel = false;
245
    if (remove)
246
        removeFileOnCropCancel = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
247
248
    currentCropImage = $('<img>').attr('src', url);
0 ignored issues
show
Bug introduced by
The variable currentCropImage seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.currentCropImage.
Loading history...
249
    $('#cropperArea').html("");
250
    $('#cropperArea').append(currentCropImage);
251
252
    autoCrop = false;
0 ignored issues
show
Bug introduced by
The variable autoCrop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.autoCrop.
Loading history...
253
    aspectRatio = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as aspectRatio. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
Bug introduced by
The variable aspectRatio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aspectRatio.
Loading history...
254
    $('#cropper-btn-cancel').show();
255
256
    console.log(cropperHideCancel);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable cropperHideCancel seems to be never declared. If this is a global, consider adding a /** global: cropperHideCancel */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
257
    if (cropperHideCancel == 'true') {
258
        $('#cropper-btn-cancel').hide();
259
    }
260
261
262
    if (ratio) {
263
        autoCrop = true;
264
        aspectRatio = ratio;
265
        $('.cropper-ratio-btn-group').hide();
266
    }
267
268
    setTimeout(function () {
269
        cropper = currentCropImage.cropper({
270
            viewMode: 1,
271
            background: false,
272
            zoomable: false,
273
            autoCrop: autoCrop,
274
            aspectRatio: aspectRatio,
275
        });
276
    }, 1000)
277
}
278
279
function stopCrop(id) {
0 ignored issues
show
Unused Code introduced by
The parameter id is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
280
    $('#cropperModal').modal('hide');
281
    if (removeFileOnCropCancel)
282
        removeFile(currentCroppingImageId);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
283
}
284
285
function cropImage() {
286
    сropBoxData = cropper.cropper('getCropBoxData');
0 ignored issues
show
Bug introduced by
The variable сropBoxData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.сropBoxData.
Loading history...
287
    imageData = cropper.cropper('getImageData');
0 ignored issues
show
Bug introduced by
The variable imageData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.imageData.
Loading history...
288
    canvasData = cropper.cropper('getCanvasData');
0 ignored issues
show
Bug introduced by
The variable canvasData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.canvasData.
Loading history...
289
    ratio = imageData.height / imageData.naturalHeight;
0 ignored issues
show
Bug introduced by
The variable ratio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ratio.
Loading history...
290
    cropLeft = (сropBoxData.left - canvasData.left) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropLeft seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropLeft.
Loading history...
291
    cropTop = (сropBoxData.top - canvasData.top) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropTop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropTop.
Loading history...
292
    cropWidth = сropBoxData.width / ratio;
0 ignored issues
show
Bug introduced by
The variable cropWidth seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropWidth.
Loading history...
293
    cropHeight = сropBoxData.height / ratio;
0 ignored issues
show
Bug introduced by
The variable cropHeight seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropHeight.
Loading history...
294
    rotated = imageData.rotate;
0 ignored issues
show
Bug introduced by
The variable rotated seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.rotated.
Loading history...
295
296
    data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
297
        id: currentCroppingImageId,
298
        width: cropWidth,
299
        height: cropHeight,
300
        top: cropTop,
301
        left: cropLeft,
302
        rotated: rotated,
303
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
304
    };
305
306
    removeFileOnCropCancel = false;
307
308
    $.ajax({
309
        url: yii2CropRoute,
0 ignored issues
show
Bug introduced by
The variable yii2CropRoute seems to be never declared. If this is a global, consider adding a /** global: yii2CropRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
310
        'method': 'POST',
311
        data: data,
312
        success: function (response) {
313
            id = '#yii2-file-object-' + currentCroppingImageId;
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
314
            if ($(id).find('img').length)
315
                $(id).find('img').attr('src', response);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
316
            else {
317
                $(id).css('background-image', 'none');
318
                $(id).css('background-image', 'url(' + response + ')');
319
            }
320
            stopCrop();
321
            f12notification.info(FileSavedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileSavedText seems to be never declared. If this is a global, consider adding a /** global: FileSavedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
322
        },
323
        error: function (response) {
324
            processError(response);
325
        }
326
    })
327
}
328
329
function showRenameFileForm(id, event) {
330
    var blockId = '#yii2-file-object-' + id;
331
    var title = $(blockId).attr('title');
332
    currentRenamingFileId = id;
333
    $('#yii2-file-title-editor').css('top', event.clientY).css('left', event.clientX - 70).fadeIn(100);
334
    $('#yii2-file-title-editor input').val(title).focus();
335
}
336
337
function showAltForm(id, event) {
338
    var blockId = '#yii2-file-object-' + id;
339
    var alt = $(blockId).data('alt');
340
    console.log(alt);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
341
    currentRenamingFileId = id;
342
    $('#yii2-file-alt-editor').css('top', event.clientY).css('left', event.clientX - 70).fadeIn(100);
343
    $('#yii2-file-alt-editor input').val(alt).focus();
344
}
345
346
function hideYii2FileTitleEditor() {
347
    $('#yii2-file-title-editor').fadeOut(100);
348
    currentRenamingFileId = null;
349
}
350
351
function hideYii2FileAltEditor() {
352
    $('#yii2-file-alt-editor').fadeOut(100);
353
    currentRenamingFileId = null;
354
}
355
356
function saveFileTitle() {
357
    $('#yii2-file-title-editor').fadeOut(100);
358
    val = $('#yii2-file-title-editor input').val();
0 ignored issues
show
Bug introduced by
The variable val seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.val.
Loading history...
359
    blockId = '#yii2-file-object-' + currentRenamingFileId;
0 ignored issues
show
Bug introduced by
The variable blockId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.blockId.
Loading history...
360
    $(blockId).attr('title', val);
361
    $(blockId).attr('data-title', val);
362
363
    $.ajax({
364
            url: yii2RenameRoute,
0 ignored issues
show
Bug introduced by
The variable yii2RenameRoute seems to be never declared. If this is a global, consider adding a /** global: yii2RenameRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
365
            method: 'POST',
366
            data: {id: currentRenamingFileId, title: val, _fileFormToken: yii2FileFormToken},
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
367
            success: function () {
368
                f12notification.info(FileRenamedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileRenamedText seems to be never declared. If this is a global, consider adding a /** global: FileRenamedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
369
            },
370
            error: function (response) {
371
                processError(response);
372
            }
373
        }
374
    );
375
    currentRenamingFileId = null;
376
}
377
378
function saveFileAlt() {
379
    $('#yii2-file-alt-editor').fadeOut(100);
380
    val = $('#yii2-file-alt-editor input').val();
0 ignored issues
show
Bug introduced by
The variable val seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.val.
Loading history...
381
    blockId = '#yii2-file-object-' + currentRenamingFileId;
0 ignored issues
show
Bug introduced by
The variable blockId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.blockId.
Loading history...
382
    $(blockId).data('alt', val)
383
384
    $.ajax({
385
            url: yii2AltRoute,
0 ignored issues
show
Bug introduced by
The variable yii2AltRoute seems to be never declared. If this is a global, consider adding a /** global: yii2AltRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
386
            method: 'POST',
387
            data: {id: currentRenamingFileId, alt: val, _fileFormToken: yii2FileFormToken},
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
388
            success: function () {
389
                f12notification.info(FileRenamedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileRenamedText seems to be never declared. If this is a global, consider adding a /** global: FileRenamedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
390
            },
391
            error: function (response) {
392
                processError(response);
393
            }
394
        }
395
    );
396
    currentRenamingFileId = null;
397
}
398
399
$(document).ready(function () {
400
    setInterval(function () {
401
        sortableFiles()
402
    }, 2000);
403
404
    sortableFiles();
405
406
    initCropperLayout();
407
408
});
409
410
411